@extends('layout.master')

@section('title','游戏详情')

@section('css')
    @parent
    <link href="{{ asset('plugins/bower_components/summernote/dist/summernote.css') }}" rel="stylesheet"/>
    <!-- animation CSS -->
    <link href="{{ asset('css/animate.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/icheck/skins/all.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/bootstrap-switch/bootstrap-switch.min.css') }}" rel="stylesheet">
@endsection
@section('main')
    <div class="white-box">
        <form class="form-horizontal form-material" method="post" enctype="multipart/form-data">
            <div class="row">
                <div class="col-md-3 col-sm-3">
                    <div class="form-group">
                        <label class="col-md-12">更多科室文字</label>
                        <div class="col-md-12">
                            <input type="text" name="ks_more_title" id="ks-more-title"
                                   value="{{ $config->ks_more_title }}"
                                   class="form-control form-control-line" required>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">更多科室图片</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="ks-more-pic" class="dropify" name="ks_more_pic"
                                   data-default-file="{{ $config->ks_more_pic }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">更多话题图片</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="ht-more-pic" class="dropify" name="ht_more_pic"
                                   data-default-file="{{ $config->ht_more_pic }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-3 col-sm-3">
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-12">分享邀请标题</label>
                            <div class="col-md-12">
                                <input type="text" name="share_invite_title" id="share-invite-title"
                                       value="{{ $config->share_invite_title }}"
                                       class="form-control form-control-line" required>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-12">分享帖子标题</label>
                            <div class="col-md-12">
                                <input type="text" name="share_posting_title" id="share-posting-title"
                                       value="{{ $config->share_posting_title }}"
                                       class="form-control form-control-line" required>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-12">分享游戏标题</label>
                            <div class="col-md-12">
                                <input type="text" name="share_game_title" id="share-game-title"
                                       value="{{ $config->share_game_title }}"
                                       class="form-control form-control-line" required>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">分享邀请图片</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="share-invite-pic" class="dropify" name="share_invite_pic"
                                   data-default-file="{{ $config->share_invite_pic }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">分享帖子图片</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="share-posting-pic" class="dropify" name="share_posting_pic"
                                   data-default-file="{{ $config->share_posting_pic }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">分享游戏图片</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="share-game-pic" class="dropify" name="share_game_pic"
                                   data-default-file="{{ $config->share_game_pic }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
            </div>
        </form>
        <div class="form-group">
            <button class="fcbtn btn btn-success btn-outline btn-1e waves-effect" id="modify">修改
            </button>
        </div>
    </div>

@endsection
@section('js')
    @parent
    <script src="{{ asset('js/myself.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/Magnific-Popup-master/dist/jquery.magnific-popup.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/Magnific-Popup-master/dist/jquery.magnific-popup-init.js') }}"></script>

    <script>

        $("#modify").click(function (e) {
            e.preventDefault();
            var ks_more_title = $("#ks-more-title").val();
            var share_invite_title = $("#share-invite-title").val();
            var share_posting_title = $("#share-posting-title").val();
            var share_game_title = $("#share-game-title").val();
            var ks_more_pic = document.getElementById("ks-more-pic").files;
            var ht_more_pic = document.getElementById("ht-more-pic").files;
            var share_invite_pic = document.getElementById("share-invite-pic").files;
            var share_posting_pic = document.getElementById("share-posting-pic").files;
            var share_game_pic = document.getElementById("share-game-pic").files;

            var data = new FormData();
            data.append('ks_more_title', ks_more_title);
            data.append('share_invite_title', share_invite_title);
            data.append('share_posting_title', share_posting_title);
            data.append('share_game_title', share_game_title);
            if (ks_more_pic.length && ((ks_more_pic[0].type).indexOf("image/") !== -1)) {
                data.append('ks_more_pic', ks_more_pic[0]);
            }
            if (ht_more_pic.length && ((ht_more_pic[0].type).indexOf("image/") !== -1)) {
                data.append('ht_more_pic', ht_more_pic[0]);
            }
            if (share_invite_pic.length && ((share_invite_pic[0].type).indexOf("image/") !== -1)) {
                data.append('share_invite_pic', share_invite_pic[0]);
            }
            if (share_posting_pic.length && ((share_posting_pic[0].type).indexOf("image/") !== -1)) {
                data.append('share_posting_pic', share_posting_pic[0]);
            }
            if (share_game_pic.length && ((share_game_pic[0].type).indexOf("image/") !== -1)) {
                data.append('share_game_pic', share_game_pic[0]);
            }

            swal({
                    title: "",
                    text: "确定修改么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({

                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: "/system/appConfig",
                        type: "POST",
                        data: data,
                        cache: false,
                        contentType: false,
                        async: false,
                        processData: false,
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },

                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            } else {
                                swal(data.message);
                            }
                        }
                    })
                }
            );
        });

        $('.role-add').submit(function (e) {
            e.preventDefault();
            var file = document.getElementById("role-add").files;
            if (!file.length) {
                swal('没有获取到图片');
                return false;
            }
            var formData = new FormData();
            formData.append('pic', file[0]);

            swal({
                    title: "",
                    text: "确定添加吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        type: "POST",
                        url: '/runGame/role/add',
                        data: formData,
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        cache: false,
                        contentType: false,
                        async: false,
                        processData: false,
                        error: function (err) {
                            for (var j in err.responseJSON) {
                                err.responseJSON[j].forEach(function (item, index) {
                                    swal(item);
                                })
                            }
                        },
                        success: function (data) {
                            console.log(data.message);
                            if (data.status === 1) {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            } else {
                                swal(data.message);
                            }
                        }
                    });
                }
            );
        });


        obj.on('click', '.btn-del', function () {
            var id = $(this).data('id');
            swal({
                    title: "",
                    text: "确定删除么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/runGame/role/del/' + id,
                        type: 'POST',
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });
    </script>
@endsection